import Http, {ReqProps} from "@/common/http";
import {SelectTreeData} from "@/components/ant-ext/HTreeSelect";
import {BaseEntitys} from "@/common/httptypes";

// 部门--//后期需整改数据-没用的删掉
export type SysDepartTree = {
    checked?: boolean
    del?: boolean
    deptCode?: string
    deptName: string
    id: string
    managerId?: string
    managerName?: string
    mobile?: string
    chparentIdecked?: string
    children?: SysDepartTree[]
    type?:string
}& BaseEntitys


export type SysDepartTreePlus = {
    key: string
    parentId: string
    title: string
    mobile: string
    children: SysDepartTreePlus[]
}


export function OrgArrIndex(arr: any, data: any) {
    for (let i in data) {
        let item = data[i];
        // eslint-disable-next-line @typescript-eslint/no-array-constructor
        let children = new Array();
        if (item.children && item.children.length > 0) {
            OrgArrIndex(children, item.children);
        }
        arr.push({
            key: item.id,
            parentId: item.parentId,
            mobile: item.mobile,
            title: item.deptName,
            children: children,
        });

    }
    return arr
}

class SysDepart {

    RowKey = "id"
    EDIT = "deparManagementEdit"
    ADD = "deparManagementAdd"
    DEL = "deparManagementDelete"
    MAPPING = {deparManagementEdit: "编辑部门", deparManagementAdd: "新增部门"}



    selectTree(props: ReqProps<SysDepartTree[]>) {
        Http.doGet("/dept/getTree", props)
    }

    treeView(props: ReqProps<SysDepartTree[]>) {
        Http.doGet("/api/org/tree", props)
    }

    doEdit(props: ReqProps<void>) {
        Http.doPost("/dept/updateById", props)
    }

    doResort(props: ReqProps<void>) {
        Http.doPost("/api/org/resort", props)
    }

    doSave(props: ReqProps<void>) {
        Http.doPost("/dept/save", props)
    }

    delete(props: ReqProps<void>) {
        Http.doDelete("/dept/deleteById", props)
    }
    // selectTree(props: ReqProps<SelectTreeData[]>) {
    //     Http.doGet("/api/org/selectTree", props)
    // }
}

// eslint-disable-next-line import/no-anonymous-default-export
export default new SysDepart()